package com.gruopbuying.agent.service.impl;

import com.gruopbuying.agent.dao.StoreAgentAccountDao;
import com.gruopbuying.agent.pojo.CommonConstants;
import com.gruopbuying.agent.pojo.StoreAgentAccountDO;
import com.gruopbuying.agent.pojo.StoreOperDTO;
import com.gruopbuying.agent.pojo.StoreShopManagePageDTO;
import com.gruopbuying.agent.service.StoreAgentAccountService;
import com.gruopbuying.agent.utils.PageUtils;
import com.gruopbuying.agent.utils.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class StoreAgentAccountServiceImpl implements StoreAgentAccountService{
    public static final Logger logger = LoggerFactory.getLogger(StoreAgentAccountServiceImpl.class);
    @Autowired
    private StoreAgentAccountDao storeAccountDao;




    //查询数据
    @Override
    public List<StoreAgentAccountDO> list(Map<String, Object> map) {
        return storeAccountDao.list(map);
    }

    //查询数量
    @Override
    public int count(Map<String, Object> map) {
        return storeAccountDao.count(map);
    }

    //查询服务商账号
    @Override
    public StoreAgentAccountDO get(String accountId) {
        return storeAccountDao.get(accountId);
    }


    public StoreAgentAccountDO getByAccountName(String accountName) {
        Map map_repeat = new HashMap();
        map_repeat.put("accountName", accountName);
        List<StoreAgentAccountDO> list_repeat = this.storeAccountDao.list(map_repeat);
        if (list_repeat.size() > 0) {
            return list_repeat.get(0);
        }
        return null;
    }






    @Override
    public PageUtils storeMainInfoListByAgent(Map<String, Object> map) {
        map.put("delflag", CommonConstants.COMMON_FLAG_UNDEL);
        map.put("sort", "createOpeTime");
        map.put("order", "desc");
        Query query = new Query(map);
        List<StoreShopManagePageDTO> smi= storeAccountDao.getListByManagePage(query);
        map.remove("limit");
        map.remove("page");
        query = new Query(map);
        List<StoreShopManagePageDTO> totalList =storeAccountDao.getListByManagePage(query);
        PageUtils pageUtil = new PageUtils(smi, totalList.size());
        return pageUtil;
    }

    @Override
    public PageUtils getStoreOperList(Map<String, Object> map) {
        /*通过代理商id获取服务商列表*/
        map.put("delflag", CommonConstants.COMMON_FLAG_UNDEL);
        map.put("sort", "createOpeTime");
        map.put("order", "desc");
        Query query = new Query(map);
        List<StoreOperDTO> smi = storeAccountDao.getStoreOpersList(query);
        map.remove("limit");
        map.remove("page");
        query = new Query(map);
        List<StoreOperDTO> totalList = storeAccountDao.getStoreOpersList(query);
        PageUtils pageUtil = new PageUtils(smi, totalList.size());
        return pageUtil;
    }


}
